﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

namespace Terraria.ModLoader
{
	// Token: 0x0200017A RID: 378
	public static class BackgroundTextureLoader
	{
		// Token: 0x06000F38 RID: 3896 RVA: 0x00401D34 File Offset: 0x003FFF34
		internal static int ReserveBackgroundSlot()
		{
			int result = BackgroundTextureLoader.nextBackground;
			BackgroundTextureLoader.nextBackground++;
			return result;
		}

		// Token: 0x06000F39 RID: 3897 RVA: 0x0000E5E0 File Offset: 0x0000C7E0
		public static int GetBackgroundSlot(string texture)
		{
			if (BackgroundTextureLoader.backgrounds.ContainsKey(texture))
			{
				return BackgroundTextureLoader.backgrounds[texture];
			}
			return -1;
		}

		// Token: 0x06000F3A RID: 3898 RVA: 0x00401D54 File Offset: 0x003FFF54
		internal static void ResizeAndFillArrays()
		{
			Array.Resize<Texture2D>(ref Main.backgroundTexture, BackgroundTextureLoader.nextBackground);
			Array.Resize<int>(ref Main.backgroundHeight, BackgroundTextureLoader.nextBackground);
			Array.Resize<int>(ref Main.backgroundWidth, BackgroundTextureLoader.nextBackground);
			Array.Resize<bool>(ref Main.backgroundLoaded, BackgroundTextureLoader.nextBackground);
			foreach (string text in BackgroundTextureLoader.backgrounds.Keys)
			{
				int num = BackgroundTextureLoader.backgrounds[text];
				Main.backgroundTexture[num] = ModLoader.GetTexture(text);
				Main.backgroundWidth[num] = Main.backgroundTexture[num].Width;
				Main.backgroundHeight[num] = Main.backgroundTexture[num].Height;
				Main.backgroundLoaded[num] = true;
			}
		}

		// Token: 0x06000F3B RID: 3899 RVA: 0x0000E5FC File Offset: 0x0000C7FC
		internal static void Unload()
		{
			BackgroundTextureLoader.nextBackground = 207;
			BackgroundTextureLoader.backgrounds.Clear();
		}

		// Token: 0x040012B2 RID: 4786
		public const int vanillaBackgroundTextureCount = 207;

		// Token: 0x040012B3 RID: 4787
		private static int nextBackground = 207;

		// Token: 0x040012B4 RID: 4788
		internal static IDictionary<string, int> backgrounds = new Dictionary<string, int>();
	}
}
